<?php 
session_start(); 
	
	if (!$_SESSION["id_no"])
    {
        Header("Location: index.php");
    }
	else{
		if ($_SESSION['account_type']=='root'){
			$header="secured/header_login";
			$admin="yes";
		}
		elseif($_SESSION['account_type']=='Admin'){ 
			$header="secured/header_login";
			$admin="yes";
		}else{
			$header="header";
			$admin="no";
		}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ralimo System Panel</title>
<link rel="stylesheet" href="css/screen.css" type="text/css" media="screen" title="default" />
<link rel="stylesheet" href="css/jquery-ui-1.8.21.custom.css" type="text/css" media="screen" title="default" />
<!--[if IE]>
<link rel="stylesheet" media="all" type="text/css" href="css/pro_dropline_ie.css" />
<![endif]-->

<!--  jquery core -->
<script src="js/jquery/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/jquery/jquery-ui-1.8.21.custom.min.js" type="text/javascript"></script>


<!--  checkbox styling script -->
<script src="js/jquery/ui.core.js" type="text/javascript"></script>
<script src="js/jquery/ui.checkbox.js" type="text/javascript"></script>
<script src="js/jquery/jquery.bind.js" type="text/javascript"></script>
<script src="js/jquery/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery/geocoder.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&libraries=places&key=AIzaSyDe8jbfLwcLgh5ERFqcJUGDM_svl2foezQ&sensor=false"></script>

<script type="text/javascript">
$(function(){
	$('input').checkBox();
	$('#toggle-all').click(function(){
 	$('#toggle-all').toggleClass('toggle-checked');
	$('#mainform input[type=checkbox]').checkBox('toggle');
	return false;
	});
});
</script>  

<![if !IE 7]>

<!--  styled select box script version 1 -->
<script src="js/jquery/jquery.selectbox-0.5.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	$('.styledselect').selectbox({ inputClass: "selectbox_styled" });
});
</script>
 

<![endif]>

<!--  styled select box script version 2 --> 
<script src="js/jquery/jquery.selectbox-0.5_style_2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	$('.styledselect_form_1').selectbox({ inputClass: "styledselect_form_1" });
	$('.styledselect_form_2').selectbox({ inputClass: "styledselect_form_2" });
});
</script>

<!--  styled select box script version 3 --> 
<script src="js/jquery/jquery.selectbox-0.5_style_2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	$('.styledselect_pages').selectbox({ inputClass: "styledselect_pages" });
});
</script>

<!--  styled file upload script --> 
<script src="js/jquery/jquery.filestyle.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
  $(function() {
      $("input.file_1").filestyle({ 
          image: "images/forms/choose-file.gif",
          imageheight : 21,
          imagewidth : 78,
          width : 310
      });
  });
</script>

<!-- Custom jquery scripts -->
<script src="js/jquery/custom_jquery.js" type="text/javascript"></script>
 
<!-- Tooltips -->
<script src="js/jquery/jquery.tooltip.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
	$('a.info-tooltip ').tooltip({
		track: true,
		delay: 0,
		fixPNG: true, 
		showURL: false,
		showBody: " - ",
		top: -35,
		left: 5
	});
});
</script> 


<!--  date picker script -->
<link rel="stylesheet" href="css/datePicker.css" type="text/css" />
<script src="js/jquery/date.js" type="text/javascript"></script>
<script src="js/jquery/jquery.datePicker.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
        $(function()
{

// initialise the "Select date" link
$('#date-pick')
	.datePicker(
		// associate the link with a date picker
		{
			createButton:false,
			startDate:'01/01/2005',
			endDate:'31/12/2020'
		}
	).bind(
		// when the link is clicked display the date picker
		'click',
		function()
		{
			updateSelects($(this).dpGetSelected()[0]);
			$(this).dpDisplay();
			return false;
		}
	).bind(
		// when a date is selected update the SELECTs
		'dateSelected',
		function(e, selectedDate, $td, state)
		{
			updateSelects(selectedDate);
		}
	).bind(
		'dpClosed',
		function(e, selected)
		{
			updateSelects(selected[0]);
		}
	);
	
var updateSelects = function (selectedDate)
{
	var selectedDate = new Date(selectedDate);
	$('#d option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
	$('#m option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
	$('#y option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
}
// listen for when the selects are changed and update the picker
$('#d, #m, #y')
	.bind(
		'change',
		function()
		{
			var d = new Date(
						$('#y').val(),
						$('#m').val()-1,
						$('#d').val()
					);
			$('#date-pick').dpSetSelected(d.asString());
		}
	);

// default the position of the selects to today
var today = new Date();
updateSelects(today.getTime());

// and update the datePicker to reflect it...
$('#d').trigger('change');
});
</script>

<!-- MUST BE THE LAST SCRIPT IN <HEAD></HEAD></HEAD> png fix -->
<script src="js/jquery/jquery.pngFix.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(document).pngFix( );
});
</script>
<script type="text/javascript">
	function delete_short_rates(id){
		var $dialog = $(
					 "<div title='Delete'>"+
					 "<p style='margin-top:40px; font-family:arial; margin-left:35px;'>Are you sure you want to delete this?</p>"+
					 "</div>"
					);
		$dialog.dialog({
			autoOpen: false,
			modal: true,
			zIndex: 9999,
			buttons:{
				"Yes":function(){
					$.post("query/delete_short_rates.php",{ short_id: id}, function(data){
						window.location.replace('ralimo_short_rates.php');
					});
					$(this).dialog("close");
				},
				"No": function(){
					$(this).dialog("close");
				}
			}	
		});
		$dialog.dialog("open");
		return false;
	}
</script>
</head>
<body> 

<?php 
include("template/$header.php");
$page = (isset($_GET['page']))?$_GET['page']:'home';
		
	$id = $_GET['id'];
	require "query/db_connection.php";
	
	$limit = 15;
	$query ="SELECT
			  COUNT(*) as num
			  FROM
			  ralimoratesdetail
			  WHERE
			  ratetype = 'short'
			  ";
	$total_pages = mysql_fetch_array(mysql_query($query));
	$total_pages = $total_pages['num'];
	
	$stages = 3;
	$page = mysql_real_escape_string($_GET['idx']);
	//$page = $_GET['idx'];
	if($page){
		$start = ($page - 1) * $limit; 
	}else{
		$start = 0;	
	}
	
	$sql2 = "SELECT 
				ra.cityname, 
				ra.vehicletype, 
				ra.vehiclemodel, 
				ra.capacity, 
				ra.cancellationpolicy, 
				ra.availability,
				rd.id,
				rd.currency,
				rd.destination,
				rd.minimumhr,
				rd.rate
				FROM 
				ralimorates ra
				LEFT JOIN ralimoratesdetail AS rd ON ra.id = rd.ralimorateid
				LEFT JOIN ralimorateservices AS rs ON ra.id = rs.ralimorateid
				WHERE
				 rd.ratetype = 'short'
				 ORDER BY ra.cityname
				 LIMIT $start, $limit";
	$res2 = mysql_query($sql2);
	
	
?>
<!--  start nav-outer-repeat................................................... END -->
<div class="clear"></div>
<!-- start content-outer ........................................................................................................................START -->
<div id="content-outer">
<!-- start content -->		
	<div id="content">

	<!--  start page-heading -->
	<div id="page-heading">
		<h1>Ralimo Short Rates</h1>
	</div>
	<!-- end page-heading -->
	<div id="affiliate_submenus">
			<a  href="panel.php?page=add_ralimorates"><img style="border:none;" alt="add ralimo rates" src="images/forms/add_ralimo_rates.png" /></a>
	</div>

	<div id="ralimo_buttons">
		<a href="panel.php?page=ralimo_rates"><img style="border:none;" alt="airport rate" src="images/forms/airport_rate.png" /></a>
		<a href="ralimo_hourly_rates.php"><img style="border:none;" alt="hourly rate" src="images/forms/hourly_rate.png" /></a>
		<a href="ralimo_short_rates.php"><img style="border:none;" alt="short rate" src="images/forms/short_rates.png" /></a>
	</div>
	
	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td>
		<!--  start content-table-inner ...................................................................... START -->
		<div id="content-table-inner">
		
			<!--  start table-content  -->
			<div id="table-content">
		
				<!--  start product-table ..................................................................................... -->
				<form id="mainform" action="">
				<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
				<tr>
					<th class="table-header-check" id="head">No.#</th>
					<th class="table-header-repeat line-left minwidth-1" width="280px;"><a href="">City:</a></th>
					<th class="table-header-repeat line-left minwidth-1" width="280px;"><a href="">Vehicle Type:</a></th>
					<th class="table-header-repeat line-left" width="280px;"><a href="">Vehicle Model:</a></th>
					<th class="table-header-repeat line-left" ><a href="">Capacity:</a></th>
					<th class="table-header-repeat line-left" width="280px;"><a href="">Destination:</a></th>
					<th class="table-header-repeat line-left" width="280px;"><a href="">Rate:</a></th>
					<th class="table-header-repeat line-left" width="280px;" ><a href="">Cancellation Policy:</a></th>
					<th class="table-header-options line-left"><a href="">Options</a></th>
				</tr>
				<tr>
				<?php
				  $acc_num = $start ;
				  $class_alternate = "";
				 while( $row = mysql_fetch_array($res2)){
					$acc_num  = $acc_num+1;
					echo "<tr class='".$class_alternate."'>
							 <td>".$acc_num."</td>
							 <td>".$row['cityname']."</td>
							 <td>".$row['vehicletype']."</td>
							 <td>".$row['vehiclemodel']."</td>
							 <td>".$row['capacity']."</td>
							 <td>".$row['destination']."</td>
							 <td>".$row['rate']." ".$row['currency']."</td>
							 <td>".$row['cancellationpolicy']."</td>
							 <td class='options-width'>
								<a href='edit_short_rates.php?id=".$row['id']."' title='Edit' class='icon-1 info-tooltip'></a>
								<a href='#' title='Delete' class='icon-2 info-tooltip' onclick='delete_short_rates(\"".$row['id']."\")'></a>
							</td>
						  </tr>";
					if($class_alternate == ""){
							$class_alternate = "alternate-row";
					}else{
						$class_alternate = "";
					}
				 }
				?>
				</tr>
				</table>
				<!--  end product-table................................... --> 
				</form>
			</div>
			<!--  end content-table  -->	
			<div class="clear"></div>
		 
		</div>
		<!--  end content-table-inner ............................................END  -->
		</td>
		<!--  start paging..................................................... -->
		<table border="0" cellpadding="0" cellspacing="0" id="paging-table">	
		<tr>
			<td>
				<?php
				if($_SESSION['account_type']=='User'){
					if ($page == 0){$page = 1;}
					$prev = $page - 1;	
					$next = $page + 1;							
					$lastpage = ceil($total_pages/$limit);		
					$LastPagem1 = $lastpage - 1;
		
					$paginate = '';
					if($lastpage > 1)
					{	
						$paginate .= "<div class='paginate'>";
						// Previous
						if ($page > 1){
							$paginate.= "<a href='ralimo_short_rates.php?idx=$prev'>previous</a>";
						}else{
							$paginate.= "<span class='disabled'>previous</span>";	}
						// Pages	
						if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
						{	
							for ($counter = 1; $counter <= $lastpage; $counter++)
							{
								if ($counter == $page){
									$paginate.= "<span class='current'>$counter</span>";
								}else{
									$paginate.= "<a href='ralimo_short_rates.php?idx=$counter'>$counter</a>";}					
							}
						}
						elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
						{
							// Beginning only hide later pages
							if($page < 1 + ($stages * 2))		
							{
								for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>$counter</span>";
									}else{
										$paginate.= "<a href='ralimo_short_rates.php?idx=$counter'>$counter</a>";}					
								}
								$paginate.= "...";
								$paginate.= "<a href='ralimo_short_rates.php?idx=$LastPagem1'>$LastPagem1</a>";
								$paginate.= "<a href='ralimo_short_rates.php?idx=$lastpage'>$lastpage</a>";		
							}
							// Middle hide some front and some back
							elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
							{
								$paginate.= "<a href='ralimo_short_rates.php?idx=1'>1</a>";
								$paginate.= "<a href='ralimo_short_rates.php?idx=2'>2</a>";
								$paginate.= "...";
								for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>$counter</span>";
									}else{
										$paginate.= "<a href='ralimo_short_rates.php?idx=$counter'>$counter</a>";}					
								}
								$paginate.= "...";
								$paginate.= "<a href='ralimo_short_rates.php?idx=$LastPagem1'>$LastPagem1</a>";
								$paginate.= "<a href='ralimo_short_rates.php?idx=$lastpage'>$lastpage</a>";		
							}
							// End only hide early pages
							else
							{
								$paginate.= "<a href='ralimo_short_rates.php?idx=1'>1</a>";
								$paginate.= "<a href='ralimo_short_rates.php?idx=2'>2</a>";
								$paginate.= "...";
								for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>$counter</span>";
									}else{
										$paginate.= "<a href='ralimo_short_rates.php?idx=$counter'>$counter</a>";}					
								}
							}
						}
									
								// Next
						if ($page < $counter - 1){ 
							$paginate.= "<a href='ralimo_short_rates.php?idx=$next'>next</a>";
						}else{
							$paginate.= "<span class='disabled'>next</span>";
						}
							
						$paginate.= "</div>";		
					}
						echo $paginate;
						echo '<div style="margin-left:160px; margin-top:20px;"><strong>'.$total_pages.'&nbsp;Results</strong></div>';
				}else{
					if ($page == 0){$page = 1;}
					$prev = $page - 1;	
					$next = $page + 1;							
					$lastpage = ceil($total_pages/$limit);		
					$LastPagem1 = $lastpage - 1;
		
					$paginate = '';
					if($lastpage > 1)
					{	
						$paginate .= "<div class='paginate'>";
						// Previous
						if ($page > 1){
							$paginate.= "<a href='ralimo_short_rates.php?idx=$prev'>previous</a>";
						}else{
							$paginate.= "<span class='disabled'>previous</span>";	}
						// Pages	
						if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
						{	
							for ($counter = 1; $counter <= $lastpage; $counter++)
							{
								if ($counter == $page){
									$paginate.= "<span class='current'>$counter</span>";
								}else{
									$paginate.= "<a href='ralimo_short_rates.php?idx=$counter'>$counter</a>";}					
							}
						}
						elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
						{
							// Beginning only hide later pages
							if($page < 1 + ($stages * 2))		
							{
								for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>&idx=$counter</span>";
									}else{
										$paginate.= "<a href='ralimo_short_rates.php?idx=$counter'>$counter</a>";}					
								}
								$paginate.= "...";
								$paginate.= "<a href='ralimo_short_rates.php?idx=$LastPagem1'>$LastPagem1</a>";
								$paginate.= "<a href='ralimo_short_rates.php?idx=$lastpage'>$lastpage</a>";		
							}
							// Middle hide some front and some back
							elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
							{
								$paginate.= "<a href='ralimo_short_rates.php?idx=1'>1</a>";
								$paginate.= "<a href='ralimo_short_rates.php?idx=2'>2</a>";
								$paginate.= "...";
								for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>$counter</span>";
									}else{
										$paginate.= "<a href='ralimo_short_rates.php?idx=$counter'>$counter</a>";}					
								}
								$paginate.= "...";
								$paginate.= "<a href='ralimo_short_rates.php?idx=$LastPagem1'>$LastPagem1</a>";
								$paginate.= "<a href='ralimo_short_rates.php?idx=$lastpage'>$lastpage</a>";		
							}
							// End only hide early pages
							else
							{
								$paginate.= "<a href='ralimo_short_rates.php?idx=1'>1</a>";
								$paginate.= "<a href='ralimo_short_rates.php?idx=2'>2</a>";
								$paginate.= "...";
								for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>$counter</span>";
									}else{
										$paginate.= "<a href='ralimo_short_rates.php?idx=$counter'>$counter</a>";}					
								}
							}
						}
									
								// Next
						if ($page < $counter - 1){ 
							$paginate.= "<a href='ralimo_short_rates.php?idx=$next'>next</a>";
						}else{
							$paginate.= "<span class='disabled'>next</span>";
							}
						
						$paginate.= "</div>";		
						}
						echo $paginate;
						echo '<div style="margin-left:120px; margin-top:20px;"><strong>'.$total_pages.'&nbsp;Results</strong></div>';
					}
			?>
			</td>
		</tr>
		</table>
			<!--  end paging................ -->
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>
		
<!--  end content -->
<div class="clear">&nbsp;</div>
</div>
<!--  end content-outer........................................................END -->

<div class="clear">&nbsp;</div>
    
<?php include"template/footer.php"; ?>
 
</body>
</html>